﻿<template>
  <a-modal
    title="编辑支付下单"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="支付授权码电子凭证线上渠道授权返回 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入支付授权码电子凭证线上渠道授权返回 " v-decorator="['payauthno']" />
        </a-form-item>
        <a-form-item label="待支付订单号费用上传返回 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入待支付订单号费用上传返回 " v-decorator="['payordid']" />
        </a-form-item>
        <a-form-item label="支付订单对应的token费用上传返回 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入支付订单对应的token费用上传返回 " v-decorator="['paytoken']" />
        </a-form-item>
        <a-form-item label="定点机构编码 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入定点机构编码 " v-decorator="['orgcodg']" />
        </a-form-item>
        <a-form-item label="业务流水号每一次请求唯一 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入业务流水号每一次请求唯一 " v-decorator="['orgbizser']" />
        </a-form-item>
        <a-form-item label="收费批次号与费用上传一致 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入收费批次号与费用上传一致 " v-decorator="['chrgbchno']" />
        </a-form-item>
        <a-form-item label="费用类别与费用上传一致 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入费用类别与费用上传一致 " v-decorator="['feetype']" />
        </a-form-item>
        <a-form-item label="就诊事件ID与费用上传一致 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入就诊事件ID与费用上传一致 " v-decorator="['mdtrtid']" />
        </a-form-item>
        <a-form-item label="扩展数据可参考FSI的接口要求 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入扩展数据可参考FSI的接口要求 " v-decorator="['expcontent']" />
        </a-form-item>
        <a-form-item label="个账使用标识为空时默认使用费用上传时的值 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入个账使用标识为空时默认使用费用上传时的值 " v-decorator="['acctusedflag']" />
        </a-form-item>
        <a-form-item v-show="false"><a-input v-decorator="['iD']" /></a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {
    Nitf6202InputDataEdit
  } from '@/api/modular/main/Nitf6202InputDataManage'
  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      // 初始化方法
      edit (record) {
        this.visible = true
        setTimeout(() => {
          this.form.setFieldsValue(
            {
              iD: record.iD,
              payauthno: record.payauthno,
              payordid: record.payordid,
              paytoken: record.paytoken,
              orgcodg: record.orgcodg,
              orgbizser: record.orgbizser,
              chrgbchno: record.chrgbchno,
              feetype: record.feetype,
              mdtrtid: record.mdtrtid,
              expcontent: record.expcontent,
              acctusedflag: record.acctusedflag
            }
          )
        }, 100)
      },
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            Nitf6202InputDataEdit(values).then((res) => {
              if (res.success) {
                this.$message.success('编辑成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('编辑失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
